<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/public.css">
</head>
<body>
    <!-- clearRect 清空给定矩形内的指定像素 -->

    <canvas id="myCanvas1" width="300" height="150" style="border:1px solid #d3d3d3;"></canvas>

    <script>
        var a = document.getElementById('myCanvas1');
        var atx = a.getContext('2d');
        atx.fillStyle = 'red';
        atx.fillRect(0,0,300,150)
        atx.clearRect(20,20,100,50);
    </script>
</body>
</html>